package com.loren.demo04.simple;

import lombok.*;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@AllArgsConstructor
@RequestMapping("/demo2")
public class RedisDemo2Controller {

    private final RedisTemplate<String, Object> redisTemplate;

    @GetMapping
    public Date demo() {
        this.redisTemplate.opsForValue().set("demo2:aaa", new Date());
        this.redisTemplate.opsForList().rightPush("demo2:list", new Entity(1, "111", new Date()));
        this.redisTemplate.opsForList().rightPush("demo2:list", new Entity(2, "222", new Date()));
        Entity entity = (Entity) this.redisTemplate.opsForList().rightPop("demo2:list");
        System.out.println(entity);
        return (Date) this.redisTemplate.opsForValue().get("demo2:aaa");
    }

    @Getter
    @Setter
    @ToString
    @NoArgsConstructor
    @AllArgsConstructor
    static class Entity {
        private Integer id;
        private String name;
        private Date birthday;
    }
}
